Kill a Process with the Help of /proc/<pid>/stat
/proc/<pid>/stat is a unique file defined for each process and it can be accessed with the process id.
Reading the file for our dummy process gives the following output:
Command:
cat /proc/326/stat
Output:
Here we get the name of the process within parentheses as the second word of the output.
This name can be used with pkill to kill that process.
pkill sleep
Now to kill it with only a partial name:
pkill -f pro
Here we’ve only used “pro” as a pattern which got matched with the “process_1”
This wouldn’t have worked if we hadn’t used the -f flag
Issues with this approach
Again, let’s create a few new processes.
Here we have two processes that we want to kill, and we have an important process “imp_process_1” terminating which might cause unforeseen consequences.
Let’s try to kill the two processes.
We killed the important process. This is why it is important to pay attention while using this command.
How to Kill Processes by Given Partial Names in Linux
On a Unix system creates a separate environment for a program when it is executed. Everything the system needs to run the program as if there were no other programs in this environment. In Unix, each command you issue initiates or starts a new process. You initiated a process using the ls command to list the directory contents.
Simply put, a process is a running program instance. pkill is a utility, preinstalled on most Linux systems, used to terminate processes from the terminal. Processes can be killed using various attributes including partial names. Partial names, snippets, and patterns can surely be used to terminate a process on a Linux machine however it may backfire to kill processes without their unique id. pkill is a powerful command that can terminate/kill processes.
Contact Us